package com.project.controller;

import com.github.pagehelper.PageInfo;
import com.project.entity.Order1;
import com.project.entity.RestPOJO;
import com.project.entity.Users;
import com.project.service.AdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags="管理员用户管理接口")//tags:说明信息
public class AdminController {

    @Autowired
    private AdminService adminService;


    @ApiOperation(
            value = "查询所有租户信息",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    //方法的参数说明
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="currentPage",value="当前页",required=true),
            @ApiImplicitParam(paramType="query",name="pageSize",value="每页显示的条目数",required=true)
    })

    @RequestMapping("/selAllTenant")
    public RestPOJO selAllTenant(Integer currentPage,Integer pageSize){
        RestPOJO restPOJO = new RestPOJO();
        PageInfo<Users> allUser = adminService.selAllUser(1, currentPage, pageSize);
        if(allUser != null && allUser.getList().size() > 0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("查询成功");
            restPOJO.setData(allUser);
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("查询失败");
        }
        return restPOJO;
    }


    @ApiOperation(
            value = "查询所有出租户信息",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    //方法的参数说明
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="currentPage",value="当前页",required=true),
            @ApiImplicitParam(paramType="query",name="pageSize",value="每页显示的条目数",required=true)
    })


    @RequestMapping("/selAllLandlord")
    public RestPOJO selAllLandlord(Integer currentPage,Integer pageSize){
        RestPOJO restPOJO = new RestPOJO();
        PageInfo<Users> allUser = adminService.selAllUser(2, currentPage, pageSize);
        if(allUser != null && allUser.getList().size() > 0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("查询成功");
            restPOJO.setData(allUser);
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("查询失败");
        }
        return restPOJO;
    }


    @ApiOperation(
            value = "查询符合条件的所有租户信息",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    //方法的参数说明
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="currentPage",value="当前页",required=true),
            @ApiImplicitParam(paramType="query",name="pageSize",value="每页显示的条目数",required=true),
            @ApiImplicitParam(paramType="query",name="keyWord",value="查询条件的关键字",required=true)
    })

    @RequestMapping("/selConditionTenant")
    public RestPOJO selConditionTenant(String keyWord,Integer currentPage,Integer pageSize){
        RestPOJO restPOJO = new RestPOJO();
        PageInfo<Users> conditionUser = adminService.selConditionUser(1,keyWord, currentPage, pageSize);
        if(conditionUser != null && conditionUser.getList().size() > 0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("查询成功");
            restPOJO.setData(conditionUser);
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("查询失败");
        }
        return restPOJO;
    }

    @ApiOperation(
            value = "查询符合条件的所有出租户信息",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    //方法的参数说明
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="currentPage",value="当前页",required=true),
            @ApiImplicitParam(paramType="query",name="pageSize",value="每页显示的条目数",required=true),
            @ApiImplicitParam(paramType="query",name="keyWord",value="查询条件的关键字",required=true)
    })

    @RequestMapping("/selConditionLandlord")
    public RestPOJO selConditionLandlord(String keyWord,Integer currentPage,Integer pageSize){
        RestPOJO restPOJO = new RestPOJO();
        PageInfo<Users> conditionUser = adminService.selConditionUser(2,keyWord, currentPage, pageSize);
        if(conditionUser != null && conditionUser.getList().size() > 0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("查询成功");
            restPOJO.setData(conditionUser);
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("查询失败");
        }
        return restPOJO;
    }


    @ApiOperation(
            value = "冻结选中的用租户/出租户",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    //方法的参数说明

    @RequestMapping("/delUser")
    public RestPOJO delUser(@RequestBody Object[] ids){
        RestPOJO restPOJO = new RestPOJO();
        Integer delCount = adminService.delUser(ids);
        if(delCount > 0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("删除成功");
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("删除失败");
        }
        return restPOJO;
    }

    @ApiOperation(
            value = "恢复选中的用租户/出租户",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    //方法的参数说明

    @RequestMapping("/recoverUser")
    public RestPOJO recoverUser(@RequestBody Object[] ids){
        RestPOJO restPOJO = new RestPOJO();
        Integer delCount = adminService.recoverUser(ids);
        if(delCount > 0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("恢复成功");
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("恢复失败");
        }
        return restPOJO;
    }

    @ApiOperation(
            value = "冻结选中的用租户/出租户",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    //方法的参数说明
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="path",name="id",value="选中用户的id",required=true)
    })

    @RequestMapping("/delOneUser/{id}")
    public RestPOJO delOneUser(@PathVariable("id") Integer id){
        RestPOJO restPOJO = new RestPOJO();
        Integer delCount = adminService.delOneUser(id);
        if(delCount > 0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("删除成功");
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("删除失败");
        }
        return restPOJO;
    }

    @ApiOperation(
            value = "恢复选中的用租户/出租户",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    //方法的参数说明
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="path",name="id",value="选中用户的id",required=true)
    })
    @RequestMapping("/recoverOneUser/{id}")
    public RestPOJO recoverOneUser(@PathVariable("id") Integer id){
        RestPOJO restPOJO = new RestPOJO();
        Integer delCount = adminService.recoverOneUser(id);
        if(delCount > 0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("恢复成功");
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("恢复失败");
        }
        return restPOJO;
    }
}
